/**
 * 新增-行情价格js
 */

$(function() {
	oneCategory_select(0);
	//listFactory();
});

function oneCategory_select(parentId){
	$.ajax({
        type: 'post',
        url: '../../sys/category/selectParentId',
        data: {
        	parentId : parentId,
        	type : 0
        },
        async: false,
        success: function(data) {
        	var result = "";
        	for(var i = 0; i < data.length; i++){
        		result += "<option value='"+data[i].categoryId+"'>"+data[i].name+"</option>";
        	}
        	$("#oneCategory").append(result);
        	
        	twoCategory_select(parentId);
        }
	})
}

function twoCategory_select(parentId){
	if (parentId != 0) {
		$.ajax({
	        type: 'post',
	        url: '../../sys/category/selectParentId',
	        data: {
	        	parentId : parentId,
	        	type : 1,
	        },
	        async: false,
	        success: function(data) {
	        	var result2 = "";
	        	$("#twoCategory").html("");
	        	result2 += "<option value=''>请选择</option>";
	        	for(var i = 0; i < data.length; i++){
	        		result2 += "<option value='"+data[i].categoryId+"'>"+data[i].name+"</option>";
	        	}
	        	$("#twoCategory").append(result2);
	        	threeCategory_select(parentId);
	        }
		})
	}
}

function threeCategory_select(parentId){
	if (parentId != 0) {
		$.ajax({
	        type: 'post',
	        url: '../../sys/category/selectParentId',
	        data: {
	        	parentId : parentId,
	        	type : 2,
	        },
	        async: false,
	        success: function(data) {
	        	var result2 = "";
	        	result2 += "<option value=''>请选择</option>";
	        	for(var i = 0; i < data.length; i++){
	        		result2 += "<option value='"+data[i].categoryId+"'>"+data[i].name+"</option>";
	        	}
	        	$("#threeCategory").html(result2);
	        }
		})
	}
}

function listFactory(categoryId,categoryTwo){
	$.ajax({
        type: 'post',
        url: '../../sys/factory/listFactory',
        data: {
        	categoryId : categoryId,
        	categoryTwo : categoryTwo,
        },
        async: false,
        success: function(data) {
        	var result = "";
        	result += "<option value=''>请选择</option>";
        	for(var i = 0; i < data.length; i++){
        		result += "<option value='"+data[i].id+"'>"+data[i].name+"</option>";
        	}
        	$("#factory").html(result);
        }
	})
}
	
var vm = new Vue({
	el:'#dpLTE',
	data: {
		quotationprice: {
			content:"",
			status : 1,
			active:1
		}
	},
	methods : {
		//一级分类获取select选中值
		oneCategory_select:function(){
			var parentId = $('#oneCategory option:selected').val();
			vm.quotationprice.categoryId = parentId;
			oneCategory_select(parentId);
		},
		//二级分类获取select选中值
		twoCategory_select:function(){
			var parentId = $('#twoCategory option:selected').val();
			vm.quotationprice.categoryTwo = parentId;
			threeCategory_select(parentId);
			
			var categoryId = vm.quotationprice.categoryId;
			var categoryTwo = vm.quotationprice.categoryTwo;
			listFactory(categoryId,categoryTwo);
		},
		//三级级分类获取select选中值
		threeCategory_select:function(){
			vm.quotationprice.categoryThree = $('#threeCategory option:selected').val();
		},
		//厂名获取select选中值
		factory_select:function(){
			vm.quotationprice.factoryId = $('#factory option:selected').val();
		},
		acceptClick: function() {
			if (!$('#form').Validform()) {
		        return false;
		    }
			
		    $.SaveForm({
		    	url: '../../sys/quotationprice/save?_' + $.now(),
		    	param: vm.quotationprice,
		    	datatype: "json",
		    	success: function(data) {
		    		$.currentIframe().vm.load();
		    	}
		    });
		}
	}
})
